package notice_logic

import (
	"time"

	"gitee.com/Luna-CY/Golang-Project-Template/internal/configuration"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/context"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/errors"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/logger"
)

func (cls *Notice) SendSmsPersonLoginCode(ctx context.Context, telephone string, code string) errors.Error {
	if "" == telephone || "" == code {
		logger.SugarLogger(logger.WithRequestId(ctx), logger.WithStack()).Errorf("IGLNL_IC.N_CE.SSPLC_DE.115241 传入参数异常，电话号码为 %q，验证码为 %q", telephone, code)

		return errors.ErrorServerInternalError("IGLNL_IC.N_CE.SSPLC_DE.135254", "传入参数异常")
	}

	var params = map[string]string{
		configuration.Configuration.Sms.Template.PersonLoginCode.Params.Code: code,
	}

	if err := cls.sms.LogTimeTo(ctx, telephone, configuration.Configuration.Sms.Template.PersonLoginCode.TemplateCode, params, time.Now().Unix()); nil != err {
		return err.Relation(errors.ErrorServerInternalError("IGLNL_IC.N_CE.SSPLC_DE.195402", "发送短信失败"))
	}

	return nil
}
